package com.lms.logisticsmanagementsystem.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/index")
public class IndexController {
    @GetMapping("/index")
    public String index(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username= (String) session.getAttribute("login_username");
        if (username==null||username==""){
            return "login/login";
        }
        return "index";
    }

    @GetMapping("/home")
    public String home(Model model,HttpServletRequest request){
        HttpSession session = request.getSession();
        String username=(String) session.getAttribute("login_username");
        if (username==null||username==""){
            return "login/login";
        }
        model.addAttribute("username",username);
        return "home";
    }
}
